package drive.Controller;

import drive.Model.ChatSession;
import drive.Service.ServiceInterface.ChatSessionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/chatsession")
public class ChatSessionController {
    @Autowired
    private ChatSessionService chatSessionService;

    // 查询所有聊天会话
    @GetMapping()
    public String selectAllChatSessions() {
        return chatSessionService.findAll();
    }

    // 根据chatSessionID查询聊天会话
    @GetMapping("/{chatSessionID}")
    public String selectChatSessionByChatSessionID(@PathVariable("chatSessionID") int chatSessionID) {
        return chatSessionService.findByChatSessionID(chatSessionID);
    }

    // 根据user1ID和user2ID查询聊天会话
    @GetMapping("/user1/{user1ID}/user2/{user2ID}")
    public String selectChatSessionByUserIDs(
            @PathVariable("user1ID") int user1ID,
            @PathVariable("user2ID") int user2ID) {
        return chatSessionService.findByUserIDs(user1ID, user2ID);
    }

    // 新增聊天会话
    @PostMapping()
    public String addChatSession(@RequestBody ChatSession chatSession) {
        return chatSessionService.add(chatSession);
    }

    // 更新聊天会话
    @PutMapping()
    public String updateChatSession(@RequestBody ChatSession chatSession) {
        return chatSessionService.update(chatSession);
    }

    // 删除聊天会话
    @DeleteMapping("/{chatSessionID}")
    public String deleteChatSession(@PathVariable("chatSessionID") int chatSessionID) {
        return chatSessionService.delete(chatSessionID);
    }
}